package top.ajunnihao.core.util;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * TODO 工具包
 *
 * @author AJun
 * @version 1.0.0
 * @date 2020/5/29
 */
public class AJunUtils {

    static AtomicInteger seed = new AtomicInteger(0);

    // 字符串判空
    public static boolean isEmpty(String s) {
        return s == null || s.length() == 0;
    }

    // guid
    public static String guid() {
        String s = UUID.randomUUID().toString();
        String s2 = s.substring(0, 8) + s.substring(9, 13) + s.substring(14, 18) + s.substring(19, 23) + s.substring(24);
        return s2.toUpperCase();
    }

    // 并发下的 guid
    public static String guid2() {
        int s = seed.incrementAndGet() % 10;
        return System.currentTimeMillis() + "" + s;
    }

    // 获取文件名后缀，例如 ".mp4"
    public static String getSuffix(String filePath) {
        int p1 = filePath.lastIndexOf('.');
        if (p1 > 0) {
            String suffix = filePath.substring(p1);
            //后缀长度必须小于10
            if (suffix.length() < 10) {
                // 后缀中不能有路径分隔符
                if (suffix.indexOf('/') < 0 && suffix.indexOf('\\') < 0) {
                    return suffix.toLowerCase();
                }
            }
        }
        return "";
    }

}
